package ibmetp.mis.controller.dept;

import ibmetp.mis.common.Constants;
import ibmetp.mis.common.Message;
import ibmetp.mis.service.DeptService;
import ibmetp.mis.serviceImpl.DeptServiceImpl;
import ibmetp.mis.vo.Dept;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

/**
 * Servlet implementation class DeptUpdateServlet
 */
public class DeptUpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeptUpdateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("Calling DeptUpdateServlet...");
		request.setCharacterEncoding(Constants.ENCODING_UTF8);
		
		//获取用户参数
		Dept dept=new Dept();
		dept.setDeptId(Long.valueOf(request.getParameter("deptId")));
		dept.setDeptNo(request.getParameter("deptNo"));
		dept.setDeptName(request.getParameter("deptName"));
		//System.out.println(request.getParameter("userName"));

		
		//更新用户
		DeptService ds=new DeptServiceImpl();		
		String result=ds.updateDept(dept);
		System.out.println(dept);
		
		//如果有返回消息，则将消息发回页面
		if(result!=null){			
			response.setCharacterEncoding(Constants.ENCODING_UTF8);
			response.getWriter().print(JSONObject.fromObject(new Message(result)));
		}
	}

}
